<script setup lang="ts">
import { onMounted, ref } from "vue";
import { Api } from "../../assets/api/api";

//精彩推荐
const marvellousData = ref([]);
//新书推荐
const newBookData = ref<Array<Object>>([]);
const newBookFirstData = ref([]);
//   名人堂
const halloffameData = ref<Array<Object>>([]);
const halloffameFirstData = ref([]);
//大咖书单
const bigshotData = ref<Array<Object>>([]);
const bigshotFirstData = ref([]);
//热销榜
const hotsaleData = ref([]);

//获取主要数据
const getMainData = async () => {
  let { data } = await Api.requesHomeBoyData();
  let mainData = data.data.list;
  //精彩推荐
  marvellousData.value = mainData[1].list;
  //新书推荐
  newBookFirstData.value = mainData[2].list[0];
  newBookData.value.push(mainData[2].list[1]);
  newBookData.value.push(mainData[2].list[2]);
  newBookData.value.push(mainData[6].list[0]);
  //   名人堂
  halloffameFirstData.value = mainData[3].list[0];
  halloffameData.value.push(mainData[3].list[1]);
  halloffameData.value.push(mainData[3].list[2]);
  halloffameData.value.push(mainData[6].list[1]);
  //   大咖书单
  bigshotFirstData.value = mainData[4].list[0];
  bigshotData.value.push(mainData[4].list[1]);
  bigshotData.value.push(mainData[4].list[2]);
  bigshotData.value.push(mainData[6].list[2]);
  //   热销榜
  hotsaleData.value = mainData[5].list;
};

onMounted(() => {
  getMainData();
});
</script>

<template>
  <div class="boy_view">
    <!-- 精彩推荐 -->
    <div class="bist">
      <h1>精彩推荐</h1>
      <ul>
        <li v-for="item in marvellousData" :key="item.id">
          <van-image width="60" height="80" :src="item.cover" />
          <div class="font">
            <h1>
              <span>{{ item.title }}</span>
            </h1>
            <span>{{ item.author }}</span>
            <p>
              {{ item.content }}
            </p>
            <button>立即阅读</button>
          </div>
        </li>
      </ul>
    </div>
    <!-- 新书推荐 -->
    <div class="boy">
      <h1>新书推荐</h1>
      <ul>
        <li>
          <van-image width="60" height="80" :src="newBookFirstData.cover" />
          <div class="font">
            <h1>
              <span>{{ newBookFirstData.title }}</span>
            </h1>
            <span>{{ newBookFirstData.author }}</span>
            <p>
              {{ newBookFirstData.content }}
            </p>
            <button>立即阅读</button>
          </div>
        </li>
        <li v-for="item in newBookData" :key="item.id">
          <p>{{ item.title }}</p>
        </li>
      </ul>
    </div>
    <!-- 名人堂 -->
    <div class="boy">
      <h1>名人堂</h1>
      <ul>
        <li>
          <van-image width="60" height="80" :src="halloffameFirstData.cover" />
          <div class="font">
            <h1>
              <span>{{ halloffameFirstData.title }}</span>
            </h1>
            <span>{{ halloffameFirstData.author }}</span>
            <p>
              {{ halloffameFirstData.content }}
            </p>
            <button>立即阅读</button>
          </div>
        </li>
        <li v-for="item in halloffameData" :key="item.id">
          <p>{{ item.title }}</p>
        </li>
      </ul>
    </div>
    <!-- 大咖书单 -->
    <div class="boy">
      <h1>大咖书单</h1>
      <ul>
        <li>
          <van-image width="60" height="80" :src="bigshotFirstData.cover" />
          <div class="font">
            <h1>
              <span>{{ bigshotFirstData.title }}</span>
            </h1>
            <span>{{ bigshotFirstData.author }}</span>
            <p>
              {{ bigshotFirstData.content }}
            </p>
            <button>立即阅读</button>
          </div>
        </li>
        <li v-for="item in bigshotData" :key="item.id">
          <p>{{ item.title }}</p>
        </li>
      </ul>
    </div>
    <!-- 热销榜 -->
    <div class="boy_free_sale">
      <div class="classification">
        <h1 class="bestsellers">热销榜</h1>
        <ul>
          <li v-for="(item, index) in hotsaleData" :key="item.id">
            <div class="serial" style="background-color: #ff3333">
              {{ index + 1 }}
            </div>
            <p>
              <span v-if="item.category">[{{ item.category }}]</span
              >{{ item.title }}
            </p>
          </li>
        </ul>
        <h2>更多热销榜&nbsp;&nbsp;<span></span></h2>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.bist {
  margin-bottom: 10px;
  & > h1 {
    height: 38px;
    line-height: 38px;
    padding-left: 10px;
    color: #5f5f5f;
    font-size: 16px;
    border-bottom: 1px solid #dedede;
    background-color: #fff;
    font-weight: normal;
  }
  ul {
    padding: 0 10px;
    background-color: #fff;
    height: 336px;
    overflow: hidden;
    li {
      display: flex;
      padding: 15px 0;
      border-bottom: 1px solid #efefef;
    }
  }
  .font {
    width: 80.2%;
    position: relative;
    padding-left: 10px;
    h1 {
      font-weight: normal;
      font-size: 15px;
      color: #333333;
      margin-bottom: 4px;
    }
    & > span {
      font-size: 12px;
      color: #999999;
    }
    p {
      font-size: 12px;
      color: #999999;
      margin-top: 4px;
      word-break: break-all;
      text-overflow: ellipsis;
      overflow: hidden;
      display: -webkit-box;
      -webkit-line-clamp: 2; /*设置隐藏行数*/
      -webkit-box-orient: vertical;
    }
    button {
      position: absolute;
      width: 74px;
      height: 30px;
      border: 1px solid #d2d6d8;
      right: 0;
      top: -3px;
      border-radius: 2px;
      font-size: 14px;
      background-color: #f3f3f3;
    }
  }
  h2 {
    height: 44px;
    line-height: 44px;
    text-align: center;
    font-size: 14px;
    color: #333333;
    font-weight: normal;
    background-color: #fff;
    margin-bottom: 10px;
    & > span {
      display: inline-block;
      width: 5px;
      height: 10px;
      background: url("/public/img/home/right.png");
      background-size: cover;
    }
  }
}
.boy {
  margin-bottom: 10px;
  & > h1 {
    height: 38px;
    line-height: 38px;
    padding-left: 10px;
    color: #5f5f5f;
    font-size: 16px;
    border-bottom: 1px solid #dedede;
    background-color: #fff;
    font-weight: normal;
  }
  ul {
    padding: 0 10px;
    background-color: #fff;
    li {
      display: flex;
      padding: 15px 0;
      border-bottom: 1px solid #efefef;
    }
  }
  li {
    & > p {
      font-size: 15px;
      color: #333333;
    }
  }
  .font {
    width: 80.4%;
    padding-left: 10px;
    position: relative;
    h1 {
      font-weight: normal;
      font-size: 15px;
      color: #333333;
      margin-bottom: 4px;
    }
    & > span {
      font-size: 12px;
      color: #999999;
    }
    p {
      font-size: 12px;
      color: #999999;
      margin-top: 4px;
      word-break: break-all;
      text-overflow: ellipsis;
      overflow: hidden;
      display: -webkit-box;
      -webkit-line-clamp: 2; /*设置隐藏行数*/
      -webkit-box-orient: vertical;
    }
    button {
      position: absolute;
      width: 74px;
      height: 30px;
      border: 1px solid #d2d6d8;
      right: 0;
      top: -3px;
      border-radius: 2px;
      font-size: 14px;
      background-color: #f3f3f3;
    }
  }
  h2 {
    height: 44px;
    line-height: 44px;
    text-align: center;
    font-size: 14px;
    color: #333333;
    font-weight: normal;
    background-color: #fff;
    & > span {
      display: inline-block;
      width: 5px;
      height: 10px;
      background: url("/public/img/home/right.png");
      background-size: cover;
    }
  }
}
.classification {
  margin-bottom: 10px;
  margin-top: 0;
  & > h1 {
    height: 38px;
    font-size: 16px;
    color: #5f5f5f;
    outline: 1px solid #eeeeee;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 10px;
    padding-left: 10px;
    font-weight: normal;
    & > span {
      display: inline-block;
      width: 33%;
      height: 36px;
      line-height: 36px;
      text-align: center;
      font-size: 16px;
      color: #5f5f5f;
      font-weight: normal;
      &.con {
        border-bottom: 2px solid #f2503c;
      }
    }
  }
  ul {
    padding: 0 10px;
    background-color: #fff;
  }
  li {
    height: 42px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #efefef;
    .serial {
      width: 15px;
      height: 15px;
      text-align: center;
      line-height: 15px;
      border-radius: 2px;
      color: #fff;
      font-size: 13px;
      margin-right: 10px;
    }
    p {
      font-size: 15px;
      color: #333333;
      span {
        color: #666666;
        display: inline-block;
        margin-right: 6px;
      }
    }
  }
  h2 {
    height: 44px;
    line-height: 44px;
    text-align: center;
    font-size: 14px;
    color: #333333;
    font-weight: normal;
    background-color: #fff;
    margin-bottom: 20px;
    & > span {
      display: inline-block;
      width: 5px;
      height: 10px;
      background: url(https://img.xmkanshu.com/operateimg/img/img/15000/15000.png);
      background-size: cover;
    }
  }
}
</style>